<admintpl file="header" />
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">会员统计</a></li>
    </ul>
    <form class="well form-search" method="post" action="{:U('Member/statement')}">
        <label>总店列表</label>
        <select style="width:150px;" name="store_id" id="store_id">
            <option value="">请选择总店</option>
            <foreach name="storeList" item="s">
                <option value="{$s.store_id}" <if condition="$search_arr['store_id'] eq $s['store_id']">selected</if>>{$s.store_name}</option>
            </foreach>
        </select>
        <label>分店列表</label>
        <select style="width:150px;" name="store_parent_id" id="store_parent_id">
            <option value="">请选择分店</option>
            <foreach name="store_parentList" item="p">
                <option value="{$p.store_id}" <if condition="$search_arr['store_parent_id'] eq $p['store_id']">selected</if>>{$p.store_name}</option>
            </foreach>
        </select>
        <div>
            <label>统计方式</label>
            <select style="width:150px;" id="type" name="type">
                <option value="month" <if condition="$search_arr['type'] eq 'month'">selected</if> >按月统计</option>
                <option value="week"  <if condition="$search_arr['type'] eq 'week'">selected</if>>按周统计</option>
            </select>
         <div id="month_to" <if condition="$search_arr['type'] eq 'week'">style="display: none"</if>>
            <select style="width:150px;  name="searchmonth_year">
            <foreach name="year_arr" item="v" key="k">
                <option value="{$k}" <if condition="$search_arr['searchmonth_year'] eq $k">selected</if>>{$v}</option>
            </foreach>
            </select>
            <select style="width:150px;"  name="searchmonth_month">
                <foreach name="month_arr" item="v" key="k">
                    <option value="{$k}" <if condition="$search_arr['searchmonth_month'] eq $k">selected</if>>{$v}</option>
                </foreach>
            </select>
        </div>
        <div  <if condition="$search_arr['type'] eq 'month' || $search_arr['type'] eq ''">style="display: none"</if> id="week_to" >
            <select style="width:100px;"  name="searchweek_year">
                <foreach name="year_arr" item="v" key="k">
                    <option value="{$k}" <if condition="$search_arr['week']['current_year'] eq $k">selected</if>>{$v}</option>
                </foreach>
            </select>
            <select style="width:60px;"  name="searchweek_month">
                <foreach name="month_arr" item="v" key="k">
                    <option value="{$k}" <if condition="$search_arr['week']['current_month'] eq $k">selected</if>>{$v}</option>
                </foreach>
            </select>
            <select style="width:200px;"  name="searchweek_week">
                <foreach name="week_arr" item="v" key="k">
                    <option value="{$v.key}" <if condition="$search_arr['week']['current_week'] eq $v['key']">selected</if>>{$v.val}</option>
                </foreach>
            </select>
        </div>

</div>

        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger" href="{:U('Member/statement')}">清空</a>
    </form>
</div>
<div class="row">
    <div id="echartsDiv" style="width: 1200px;height:600px;margin-top: 50px;margin-left: 20px;"></div>
</div>
</body>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/layer/layer.js"></script>
<script src="__PUBLIC__/js/echarts-all.js"></script>
<input type="hidden" value='{$stat_json}' name="stat_json">
<!-- iframe自适应高度 -->
</body>
<script type="text/javascript">

    //获取统计数据
    var stat_json = JSON.parse($("[name=stat_json]").val());
    var myChart = echarts.init(document.getElementById('echartsDiv'));

    option = {
        title: {
            // text: '某地区蒸发量和降水量',
            // subtext: '纯属虚构'
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: []
        },
        toolbox: {
            show: true,
            feature: {
                dataView: {show: true, readOnly: false},
                magicType: {show: true, type: ['line', 'bar']},
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        calculable: true,
        xAxis:stat_json.xAxis,
        yAxis: [
            {
                type: 'value',

            }
        ],
        series: stat_json.series
    };
    myChart.setOption(option);

</script>
<script>

    $("#type").change(function(){
        var type = $(this).val();
        if(type == 'month'){
            $("#week_to").hide();
            $("#month_to").show();
        }else if(type == 'week'){
            $("#week_to").show();
            $("#month_to").hide();
        }
    })
    //更新周数组
    $("[name='searchweek_month']").change(function() {
        var year = $("[name='searchweek_year']").val();
        var month = $("[name='searchweek_month']").val();
        $("[name='searchweek_week']").html('');
        var url = "{:U('Member/getweekofmonth')}";
        $.post(url,{
            y:year,
            m:month
        },function(data){
            var res = JSON.parse(data)
            if (res != null) {
                for (var i = 0; i < res.length; i++) {
                    $("[name='searchweek_week']").append('<option value="' + res[i].key + '">' + res[i].val + '</option>');
                }
            }
        })
    });


    $("button.btn-add").click(function () {
        location.href = "{:U('Store/insert')}";
    })
    $("button.btn-edit").click(function () {
        location.href = "{:U('Store/revise')}&store_id="+$(this).attr('attr-id');
    })

    $("#store_id").change(function(){
        var store_id = $(this).val();
        var url = "{:U('Member/getStore')}";
        if(store_id != ''){
            var str = '<option value="">请选择分店</option>'
            $.post(url,{
                store_id:store_id
            },function(data){
                var res = JSON.parse(data);
                if(res.length > 0){
                    $.each(res,function(index,item){
                        str += "<option value='"+item.store_id+"'>"+item.store_name+"</option>";
                    })
                }
                $("#store_parent_id").html(str);
            })
        }
    })
</script>

</html>
